#include "stringSeparator.h"

stringSeparator::stringSeparator(irr::core::string<irr::c8> s, const char* sep)
{
	int debut=0;
	int taille = s.size()-1;
	for( int i = 0 ; i < (signed)s.size() ; i++)
	{
		if(s[i]==sep[0])
		{
			taille=i-debut;
			//cout<< "debut= "<<debut<<"// taille = "<<taille<<"\n";
			elements.push_back(s.subString(debut,taille));
			debut=i+1;
			taille=s.size()-1;
		}
	}
	elements.push_back(s.subString(debut,taille));
}

int stringSeparator::elementToInt(int index)
{
	int value;
	std::stringstream ss;
	ss << elements[index].c_str();
	ss >> value;
	return value;
}

bool stringSeparator::elementToBool(int index) // TODO: test this method !!
{
	return elements[index] == "true";
}

void stringSeparator::afficherElements()
{
	if(elements.size()==0)
	std::cout<<"pas de contenu dans Elements";
	else
	{
		for (int i = 0 ; i < (signed)elements.size() ; i ++)
			std::cout << "elements["<<i<<"]= "<< elements[i].c_str()<<"\n";
	}
}

